package ch07_GUI编程;

import java.awt.Color;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JLabel;

public class FontDemo {
	public static List<String> getChineseFontNames(){ 
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		String[] fonts = ge.getAvailableFontFamilyNames();
		List<String> names = new ArrayList<String>();
		for (String f : fonts) {
			if(f.charAt(0)>0x80) {
				names.add(f);
			}
		}
		
		return names;
	}
	public static void main(String[] args) {
		BaseFrame f = new BaseFrame("Font Demo");
		f.setLayout(new GridLayout(4,5,2,2));
		
		List<String> names = getChineseFontNames();
		for (int i = 0; i < Math.min(names.size(), 20); i++) {
			Font font = new Font(names.get(i),Font.PLAIN,20);
			JLabel lab = new JLabel(names.get(i));
			lab.setFont(font);
			lab.setBorder(BorderFactory.createLineBorder(Color.BLACK));
			f.add(lab);
		}
		f.showMe();
	}
}
